package com.example.fouroperations;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class MainActivity extends AppCompatActivity {

    public static final String TAG ="MainActivity";
    ArrayList<String> ques_ans; //存放生成的题目答案

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i(TAG, "onCreate: HI!");
    }

    //点击“Start”
    public void startClick(View btn) {
        Log.i(TAG, "startClick: ");

        //获取用户输入题目个数
        EditText quesNum = findViewById(R.id.quesNum);
        String ques_temp = quesNum.getText().toString();
        int ques_num = Integer.valueOf(ques_temp);

        //获取用户输入每题作答时间
        EditText countdownSet = findViewById(R.id.countdownSet);
        String countdown_temp = quesNum.getText().toString();
        int countdown = Integer.valueOf(countdown_temp);

        //生成题目
        ques_ans = generateQues(ques_num);
        Log.i(TAG, "startClick: ques_ans=" + ques_ans);
        Log.i(TAG, "startClick: ques_num=" + ques_num);
        Log.i(TAG, "startClick: countdown=" + countdown);

        //使用Buddle打包发送数据
        Intent mainIntent = new Intent(this, com.example.fouroperations.AnswerActivity.class);

        Bundle mainBdl = new Bundle();
        mainBdl.putStringArrayList("ques_ans", ques_ans);
        mainBdl.putInt("countdown", countdown);
        mainBdl.putInt("ques_num", ques_num);
        mainIntent.putExtras(mainBdl);

        Log.i(TAG, "startClick: 111");
//        startActivityForResult(mainIntent, 1);
        startActivity(mainIntent);
    }

    //随机生成题目
    public ArrayList<String> generateQues(int quesNum){

        //创建Map对象
        ArrayList<String> list = new ArrayList<String>();       //数据采用的哈希表结构
        BinaryTree bTree;

        for(int num=0; num<quesNum; num++){
            bTree = new BinaryTree(2);
            bTree.createBTree();
            list.add(bTree.toString()+"");
        }
        return list;
    }




}